package com.iknow.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.os.Process;
import android.widget.ImageView;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.file.CacheSystem;
import com.iknow.image.ImageManager;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.task.CommonTask.DownloadFileTask;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.MsgDialog;
import com.iknow.util.StringUtil;
import com.xmpp.task.LoginAsyncTask;
import java.io.File;
import java.util.Map;

public class SplashActivity extends Activity
{
  private final String TAG = "SplashActivity";
  private String filePath;
  private CommonTask.DownloadFileTask mDownLoadApkTask;
  private LoadingTask mLoadingTask;
  private ImageView mLogoImage;
  private ProfileImageCacheManager mProfileImageCacheManager;
  private LoginAsyncTask mTask;
  private TaskListener mTaskListener;
  private Map<String, Object> updateInfo = null;

  public SplashActivity()
  {
    this.filePath = null;
    this.mTaskListener = new TaskAdapter(this)
    {
      protected ProgressDialog pd = null;

      public String getName()
      {
        return null;
      }

      public void onCancelled()
      {
        if (paramGenericTask instanceof CommonTask.DownloadFileTask)
        {
          new File(SplashActivity.access$5(this.this$0)).delete();
          if (!(((Boolean)SplashActivity.access$1(this.this$0).get("isMust")).booleanValue()))
            break label55;
          Process.killProcess(Process.myPid());
        }
        while (true)
        {
          return;
          label55: SplashActivity.access$2(this.this$0);
        }
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        if (this.pd != null)
          this.pd.dismiss();
        if (paramGenericTask instanceof SplashActivity.LoadingTask)
          if (paramTaskResult == TaskResult.OK)
            if (SplashActivity.access$1(this.this$0) != null)
              this.this$0.showDialog();
        while (true)
        {
          while (true)
          {
            while (true)
            {
              do
                while (true)
                {
                  while (true)
                  {
                    return;
                    SplashActivity.access$2(this.this$0);
                  }
                  SplashActivity.access$2(this.this$0);
                  Toast.makeText(this.this$0, SplashActivity.access$3(this.this$0).getErrorMessage(), 0).show();
                }
              while (!(paramGenericTask instanceof CommonTask.DownloadFileTask));
              if (paramTaskResult != TaskResult.OK)
                break;
              SplashActivity.access$4(this.this$0);
            }
            Toast.makeText(this.this$0, "网络超时，下载升级文件失败", 0).show();
            IKnow.mCacheSystem.deleteFile(SplashActivity.access$5(this.this$0));
            if (!(((Boolean)SplashActivity.access$1(this.this$0).get("isMust")).booleanValue()))
              break;
            Process.killProcess(Process.myPid());
          }
          SplashActivity.access$2(this.this$0);
        }
      }

      public void onPreExecute()
      {
        super.onPreExecute(paramGenericTask);
        if (paramGenericTask instanceof CommonTask.DownloadFileTask)
        {
          if (this.pd == null)
            this.pd = new ProgressDialog(this.this$0);
          this.pd.setProgressStyle(1);
          this.pd.setTitle("提示");
          this.pd.setMessage("正在下载安装包，请稍后");
          this.pd.setProgress(0);
          this.pd.setMax(100);
          this.pd.setCancelable(true);
          this.pd.show();
          this.pd.setOnCancelListener(new DialogInterface.OnCancelListener(this)
          {
            public void onCancel()
            {
              if ((SplashActivity.access$0(SplashActivity.1.access$0(this.this$1)) != null) && (SplashActivity.access$0(SplashActivity.1.access$0(this.this$1)).getStatus() == AsyncTask.Status.RUNNING))
                SplashActivity.access$0(SplashActivity.1.access$0(this.this$1)).cancel(true);
            }
          });
        }
      }

      public void onProgressUpdate(, Object paramObject)
      {
        if (paramGenericTask instanceof CommonTask.DownloadFileTask)
          this.pd.setProgress(((Integer)paramObject).intValue());
      }
    };
  }

  private void initView()
  {
    requestWindowFeature(1);
    setContentView(2130903124);
    this.mLogoImage = ((ImageView)findViewById(2131296518));
    String str = IKnow.mSystemConfig.getString("logo_image_url");
    if (!(StringUtil.isEmpty(str)))
      this.mProfileImageCacheManager.displayContentBimap(this.mLogoImage, str);
    while (true)
    {
      return;
      this.mLogoImage.setImageResource(2130837661);
    }
  }

  private void install()
  {
    Intent localIntent = new Intent("android.intent.action.VIEW");
    localIntent.setDataAndType(Uri.fromFile(new File(this.filePath)), "application/vnd.android.package-archive");
    startActivity(localIntent);
    finish();
    Process.killProcess(Process.myPid());
  }

  private void onLoadingFinish()
  {
    startActivity(new Intent(this, IKnowActivity.class));
    finish();
  }

  private void startDownLoadApk()
  {
    String str1 = (String)this.updateInfo.get("updateUrl");
    String str2 = IKnow.mCacheSystem.getFilePath(str1);
    if (str2 != null)
    {
      this.filePath = str2;
      install();
    }
    while (true)
    {
      do
      {
        return;
        this.filePath = IKnow.mCacheSystem.getFile(str1).getAbsolutePath();
      }
      while ((this.mDownLoadApkTask != null) && (this.mDownLoadApkTask.getStatus() == AsyncTask.Status.RUNNING));
      this.mDownLoadApkTask = new CommonTask.DownloadFileTask();
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("url", str1);
      localTaskParams.put("file_name", this.filePath);
      this.mDownLoadApkTask.setListener(this.mTaskListener);
      CommonTask.DownloadFileTask localDownloadFileTask = this.mDownLoadApkTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localDownloadFileTask.execute(arrayOfTaskParams);
    }
  }

  private void startLoadingTask()
  {
    this.mLoadingTask = new LoadingTask(this, null);
    this.mLoadingTask.setListener(this.mTaskListener);
    this.mLoadingTask.execute(new TaskParams[0]);
  }

  public String getDescriptionByLevel(String paramString)
  {
    String str;
    if (paramString.equalsIgnoreCase("1"))
      str = "iKnow更新，此次更新点：问题修复。\n";
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            return str;
            if (!(paramString.equalsIgnoreCase("2")))
              break;
            str = "iKnow更新，此次更新点：功能改进。\n";
          }
          if (!(paramString.equalsIgnoreCase("3")))
            break;
          str = "iKnow更新，此次更新点：功能扩展。\n";
        }
        if (!(paramString.equalsIgnoreCase("4")))
          break;
        str = "iKnow更新，此次更新点：软件重大漏洞修复。\n";
      }
      str = "更新提示。\n";
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.mProfileImageCacheManager = new ProfileImageCacheManager();
    initView();
  }

  protected void onDestroy()
  {
    this.mProfileImageCacheManager.cancelImageTask();
    this.mProfileImageCacheManager.getImageManager().clear();
    super.onDestroy();
  }

  protected void onPause()
  {
    super.onPause();
  }

  protected void onResume()
  {
    startLoadingTask();
    super.onResume();
  }

  public void showDialog()
  {
    String str1;
    String str2;
    boolean bool = ((Boolean)this.updateInfo.get("isMust")).booleanValue();
    if (StringUtil.isEmpty(this.filePath))
    {
      str1 = (String)this.updateInfo.get("description");
      if (str1 != null)
        str1 = str1.replace(";", "\n\n");
      if (!(bool))
        break label91;
      str2 = "退出";
    }
    while (true)
    {
      MsgDialog.showB2Dilog(this, "iKnow更新", str1, new DialogInterface.OnClickListener(this, bool)
      {
        public void onClick(, int paramInt)
        {
          switch (paramInt)
          {
          default:
          case -1:
          case -2:
          }
          while (true)
          {
            while (true)
            {
              while (true)
              {
                return;
                SplashActivity.access$7(this.this$0);
              }
              if (!(this.val$isMust))
                break;
              Process.killProcess(Process.myPid());
            }
            SplashActivity.access$2(this.this$0);
          }
        }
      }
      , false, "现在更新", str2);
      return;
      label91: str2 = "以后再说";
    }
  }

  private class LoadingTask extends GenericTask
  {
    protected TaskResult _doInBackground()
    {
      try
      {
        Thread.sleep(2000L);
        SplashActivity.access$6(this.this$0, IKnow.mApi.checkUpdate());
        return TaskResult.OK;
      }
      catch (InterruptedException localInterruptedException)
      {
        localInterruptedException.printStackTrace();
      }
    }
  }
}